sudo mkdir -p /mnt/rootfs
sudo mkdir -p /mnt/uboot
sudo mkdir -p /mnt/kernel
dd if=/dev/zero of=rootfs-arm.ext3 bs=1M count=256

echo "hard disk partition!"
sgdisk -n 0:0:+32M -c 0:uboot rootfs-arm.ext3
sgdisk -n 0:0:0 -c 0:rootfs rootfs-arm.ext3
sgdisk -p rootfs-arm.ext3

echo "mount loop device!"
LOOPDEV=`losetup -f`
echo $LOOPDEV
sudo losetup $LOOPDEV  rootfs-arm.ext3
sudo partprobe $LOOPDEV
sudo losetup -l
ls -l /dev/loop*

echo "format disk to ext3"
echo ${LOOPDEV}p1
echo ${LOOPDEV}p2
if [ -e ${LOOPDEV}p1 ] && [ -e ${LOOPDEV}p2 ]; then
	sudo mkfs.ext3 ${LOOPDEV}p1
	sudo mkfs.ext3 ${LOOPDEV}p2
	sudo mount -t ext3 ${LOOPDEV}p1 /mnt/uboot -o loop
	sudo mount -t ext3 ${LOOPDEV}p2 /mnt/rootfs -o loop
	sudo cp -rf rootfs-arm/* /mnt/rootfs/
	sudo cp vexpress-v2p-ca9/arch/arm/boot/dts/vexpress-v2p-ca9.dtb /mnt/uboot/
	sudo cp vexpress-v2p-ca9/arch/arm/boot/uImage /mnt/uboot/
	sudo umount /mnt/rootfs/
	sudo umount /mnt/uboot/
else
	echo "${LOOPDEV} is not exit!"
fi
sudo losetup -d $LOOPDEV
